﻿using System;
using System.Data.SqlClient;
using Devv.Core.UniDataTier;

namespace BikeBouncer.BusinessLayer.Entities
{
	[Serializable]
	public class UserPasswordRecovery : BaseEntity
	{
		#region Properties

		public String RecoveryKey { get; set; }
		public DateTime DateGenerated { get; set; }
		public User User { get; set; }

		#endregion

		#region Hidden properties

		private new Int32 Id { get; set; }
		private new Boolean Active { get; set; }

		#endregion

		#region Constructor

		public UserPasswordRecovery()
		{
			User = new User();
		}

		public UserPasswordRecovery(String key)
		{
			Construct(DataAccess.UserPasswordRecovery_Get(key));
		}

		public UserPasswordRecovery(SqlDataReader reader)
		{
			Construct(reader);
		}

		#endregion	

		#region Loading

		public override void Load(SqlDataReader reader)
		{
			RecoveryKey = DataHandler.GetString(reader, "RecoveryKey");
			DateGenerated = DataHandler.GetDateTime(reader, "DateGenerated");

			User = new User();
			User.Id = DataHandler.GetInt32(reader, "UserId");
		}

		#endregion

		#region Helper methods

		public String GenerateKey()
		{
			String key = Guid.NewGuid() + "-" + User.Id + "-" + DateTime.Now.DayOfYear.ToString("000");
			return key.ToUpper();
		}

		#endregion
	}
}